<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const wang = "www.itwangyang.com"
    console.log(wang.replace('com', 'xyz'));

    const words = ['php', 'css']
    const string = "我喜欢学习css与php的知识"
    const replaceString = words.reduce((pre, word) => {
      console.log(pre); // 注意这里是循环两遍的，所以第二次，没有直接返回return，就是第二遍就是undefined，如果有直接返回那就是返回的的那个
      return pre.replace(word, `<a href="?w=${word}">${word}</a>`);
      // return 'cmd'
      // console.log(word);
    }, string)
    console.log(replaceString);
    document.body.innerHTML += replaceString
  </script>
</body>

</html>